package com.gongj;


import com.gongj.loader.MyLoader;
import com.gongj.service.UserService;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Main {

	public static void main(String[] args) {

		//加载xml
//		ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:beans.xml");
//		User user = ctx.getBean(User.class);
//		System.out.println("user = " + user);

		//启动spring容器  ----> 创建非懒加载的单例Bean
		//扫描包路径
//		AnnotationConfigApplicationContext annotationConfigApplicationContext =
//				new AnnotationConfigApplicationContext(AppConfig.class);
//		//该demo只实现了FactoryBean的逻辑
//		//com.gongj.entity.User@cac736f
//		System.out.println(annotationConfigApplicationContext.getBean("gongjFactoryBean"));
//		//com.gongj.service.GongjFactoryBean@5e265ba4
//		System.out.println(annotationConfigApplicationContext.getBean("&gongjFactoryBean"));

	    //Spirng 的生命周期
		AnnotationConfigApplicationContext annotationConfigApplicationContext =
				new AnnotationConfigApplicationContext(AppConfig.class);
		UserService userService = (UserService)annotationConfigApplicationContext.getBean("userService");
		userService.test();

		//设置类加载器
//		Thread.currentThread().setContextClassLoader(new MyLoader());
//		ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:beans.xml");
//
//		UserService userService = (UserService)ctx.getBean("userService");
//		userService.test();

	}
}
